//
//  YWMeterReadingRecordViewController.m
//  maintain
//
//  Created by 郑想 on 16/2/24.
//  Copyright © 2016年 ewin. All rights reserved.
//

#import "YWMeterReadingRecordViewController.h"
#import "YWMacro.h"
#import "UIColor+CustomColors.h"
#import "DLTabedSlideView.h"
#import "DLFixedTabbarView.h"
#import "Masonry.h"

#import "YWWaterMeterRecordVC.h"
#import "YWElectricityMeterRecordVC.h"
#import "YWGasMeterRecordVC.h"


@interface YWMeterReadingRecordViewController ()<DLTabedSlideViewDelegate>
@property (nonatomic, weak) DLTabedSlideView* tabedSlideView;
@end

@implementation YWMeterReadingRecordViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.title = @"抄表记录";
    self.view.backgroundColor = [UIColor customBackgroudColor];
    self.view.userInteractionEnabled = YES;
    
    [self autoLayoutView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    // 禁用 iOS7 返回手势
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    // 开启
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
}
- (DLTabedSlideView*)tabedSlideView
{
    if (!_tabedSlideView) {
        DLTabedSlideView* tabedSlideView = [[DLTabedSlideView alloc] init];
        tabedSlideView.delegate = self;
        tabedSlideView.baseViewController = self;
        tabedSlideView.tabItemNormalColor = [UIColor blackColor];
        tabedSlideView.tabItemSelectedColor = [UIColor customRedColor];
        tabedSlideView.tabbarTrackColor = [UIColor customRedColor];
        tabedSlideView.backgroundColor = [UIColor whiteColor];
        DLTabedbarItem* waterItem = [DLTabedbarItem itemWithTitle:@"水表" image:nil selectedImage:nil];
        DLTabedbarItem* electricityItem = [DLTabedbarItem itemWithTitle:@"电表" image:nil selectedImage:nil];
        DLTabedbarItem* gasItem = [DLTabedbarItem itemWithTitle:@"气表" image:nil selectedImage:nil];
        tabedSlideView.tabbarItems = @[ waterItem, electricityItem, gasItem ];
        [tabedSlideView buildTabbar];
        tabedSlideView.selectedIndex = 0;
        [self.view addSubview:tabedSlideView];
        _tabedSlideView = tabedSlideView;
    }
    return _tabedSlideView;
}

- (void)autoLayoutView
{
    [self.tabedSlideView mas_makeConstraints:^(MASConstraintMaker* make) {
        make.top.mas_equalTo(self.view.mas_top);//.offset(64);
        make.left.mas_equalTo(self.view.mas_left);
        make.height.mas_equalTo(self.view.mas_height);//.offset(-64);
        make.width.mas_equalTo(self.view.mas_width);
    }];
}

- (NSInteger)numberOfTabsInDLTabedSlideView:(DLTabedSlideView*)sender
{
    return self.tabedSlideView.tabbarItems.count;
}

- (UIViewController*)DLTabedSlideView:(DLTabedSlideView*)sender controllerAt:(NSInteger)index
{
    switch (index) {
        case 0: {
            YWWaterMeterRecordVC* waterMeterVC = [[YWWaterMeterRecordVC alloc] init];
            return waterMeterVC;
        }
        case 1: {
            YWElectricityMeterRecordVC* elecMeterVC = [[YWElectricityMeterRecordVC alloc] init];
            return elecMeterVC;
        }
        case 2: {
            YWGasMeterRecordVC* gasMeterVc = [[YWGasMeterRecordVC alloc] init];
            return gasMeterVc;
        }
            
        default:
            return nil;
    }
}

@end
